package hu.issue.ejb;

import hu.issue.entity.Role;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless
public class RoleServiceBean implements RoleService {
	@PersistenceContext
	private EntityManager manager;

	@SuppressWarnings("unchecked")
	@Override
	public List<Role> getRoles() {
		final Query query = this.manager.createQuery("select r from Role r");
		return query.getResultList();
	}

	@Override
	public Role findByName(final String role) {
		final Query query = this.manager.createQuery("select r from Role r where r.name = :name ");
		query.setParameter("name", role);
		return (Role) query.getSingleResult();

	}
}